import Vue from 'vue';
import App from './App';
import router from './router';
import element from './ElementUI/ElementUI';
Vue.use(element);
import axios from 'axios';
import apiConfig from '../config/api.config' //代理封装
import https from "./ElementUI/https";       //axios接口封装
Vue.prototype.$https = https;//全局注册，使用方法为:this.$https
import RegionPicker from 'vue-region-picker';//引入城市切换
import REGION_DATA from 'china-area-data';
Vue.use(RegionPicker, {
  region: REGION_DATA
});

import 'element-ui/lib/theme-chalk/index.css';
import '../theme/index.css';
import './assets/css/public.css';


import $ from "jquery";
Vue.prototype.$ = $;//全局注册，使用方法为:this.$https

Vue.prototype.$axios = axios; //全局注册，使用方法为:this.$axios


//设置本地图片路径前缀

Vue.prototype.$urls = 'http://sjxxlm.com/start/pic/';
// Vue.prototype.$urls = 'http://www.sjxxlm.com/start/pic/';
//http://sjxxlm.com/start/pic/f83d9fee9e3958b580d917099ead57e0.jpg
//http://www.sjxxlm.com/start/pic/2c17721ed66295a473704742fd541c0a.jpg



axios.defaults.baseURL = apiConfig.baseUrl;
Vue.config.productionTip = false;
Vue.prototype.$ELEMENT = {
  size: 'small',
  zIndex: 3000
};


Vue.prototype.$bus = new Vue();


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next();

  if (localStorage.getItem("accessId") && (new Date().getTime() - localStorage.getItem("loginTime")) < 12 * 60 * 60 * 1000) {
    next()
  }
  else {

    if (to.name == "Register" || to.name == "Resetword" || to.name == "HomePage" || to.name == "MessageDetails" || to.name == "MessageList" || to.name == "SearchText" || to.name == "eFooter" ){
      next();
    } else {
      sessionStorage.clear()
      localStorage.removeItem("loginTime")
      localStorage.removeItem("accessName")
      localStorage.removeItem("accessId")
      next("/Login")
    }
  }
  //next()

})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
});


// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     localStorage.removeItem('userinfo');
//     sessionStorage.removeItem('users');
//     next();
//   }

//   var userinfos = JSON.parse(localStorage.getItem("userinfo"));
//   if (userinfos) {
//     store.state.userinfo = userinfos
//     next();
//   }

//   /* 路由发生变化修改页面title */
//   if (to.meta.title) {
//     document.title = to.meta.title
//   }
//   next()
// })

